package com.isdepci.project.reference.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.project.reference.domain.ReferenceMaterial;
import com.isdepci.project.reference.service.IReferenceMaterialService;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.web.page.TableDataInfo;

/**
 * 参考材料Controller
 *
 * @author isdepci
 * @date 2023-08-23
 */
@RestController
@RequestMapping("/reference/material")
public class ReferenceMaterialController extends BaseController
{
    @Autowired
    private IReferenceMaterialService referenceMaterialService;

    /**
     * 查询参考材料列表
     */
    @PreAuthorize("@ss.hasPermi('reference:material:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReferenceMaterial referenceMaterial)
    {
        startPage();
        List<ReferenceMaterial> list = referenceMaterialService.selectReferenceMaterialList(referenceMaterial);
        return getDataTable(list);
    }

    /**
     * 导出参考材料列表
     */
    @PreAuthorize("@ss.hasPermi('reference:material:export')")
    @Log(title = "参考材料", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ReferenceMaterial referenceMaterial)
    {
        List<ReferenceMaterial> list = referenceMaterialService.selectReferenceMaterialList(referenceMaterial);
        ExcelUtil<ReferenceMaterial> util = new ExcelUtil<ReferenceMaterial>(ReferenceMaterial.class);
        return util.exportExcel(list, "material");
    }

    /**
     * 获取参考材料详细信息
     */
    @PreAuthorize("@ss.hasPermi('reference:material:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(referenceMaterialService.selectReferenceMaterialById(id));
    }

    /**
     * 新增参考材料
     */
    @PreAuthorize("@ss.hasPermi('reference:material:add')")
    @Log(title = "参考材料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReferenceMaterial referenceMaterial)
    {
        return toAjax(referenceMaterialService.insertReferenceMaterial(referenceMaterial));
    }

    /**
     * 修改参考材料
     */
    @PreAuthorize("@ss.hasPermi('reference:material:edit')")
    @Log(title = "参考材料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReferenceMaterial referenceMaterial)
    {
        return toAjax(referenceMaterialService.updateReferenceMaterial(referenceMaterial));
    }

    /**
     * 删除参考材料
     */
    @PreAuthorize("@ss.hasPermi('reference:material:remove')")
    @Log(title = "参考材料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(referenceMaterialService.deleteReferenceMaterialByIds(ids));
    }
}
